package com.sanpu.kxe.business.card.view;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sanpu.kxe.R;
import com.sanpu.kxe.base.BaseTitleActivity;
import com.sanpu.kxe.business.card.bean.BankInfoInput;
import com.sanpu.kxe.business.card.contract.AddBankSecondContract;
import com.sanpu.kxe.business.card.contract.CardConfig;
import com.sanpu.kxe.business.card.presenter.AddBankSecondPresenter;
import com.sanpu.kxe.common.interfaces.UrlConstants;
import com.sanpu.kxe.jump.imageloader.JKImageLoader;
import com.sanpu.kxe.module.dialog.HintDialog;
import com.sanpu.kxe.module.widget.EditTextWithDel;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Description：添加银行卡第二步
 * 判断卡类型、输入手机号
 * Created by 薛勇军 on 2018/7/24.
 */

public class AddBankSecondActivity extends BaseTitleActivity implements AddBankSecondContract.View {

    @Bind(R.id.card_image)
    ImageView vCardImage;
    @Bind(R.id.bank_name)
    TextView vBankName;
    @Bind(R.id.phone_number)
    EditTextWithDel vPhoneNumber;

    private AddBankSecondContract.Presenter mPresenter;

    private String logoPath;

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_add_bank_second;
    }

    @Override
    protected void initView() {
        super.initView();
        commonTitle.setTitle("添加信用卡");
        BankInfoInput infoInput = (BankInfoInput) getIntent().getSerializableExtra(CardConfig.INTENT_BANKINFO);
        logoPath = getIntent().getStringExtra(CardConfig.INTENT_LOGOPATH);
        mPresenter = new AddBankSecondPresenter(this);
        mPresenter.initDataView(infoInput);
    }

    @OnClick({R.id.next, R.id.phone_hint})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.next:
                mPresenter.onNextClick(vPhoneNumber.getText().toString());
                break;
            case R.id.phone_hint:
                TextView textView = new TextView(mContext);
                textView.setText("银行预留的手机号码是办理该银行卡时所填写的手机号码，没有预留、手机号忘记或者已停用，请联系银行客服进行更新处理。");
                new HintDialog(mContext)
                        .title("手机号说明")
                        .content(textView)
                        .show();
                break;
        }
    }

    @Override
    public void showBankInfo(String bankName) {
        if (!TextUtils.isEmpty(bankName)) {
            vBankName.setText(bankName);
        }
        JKImageLoader.getInstance().displayImage(mContext, UrlConstants.getBaseUrl() + logoPath, vCardImage);
    }

    @Override
    protected boolean hasBindEventBus() {
        return false;
    }

    @Override
    public void setPresenter(AddBankSecondContract.Presenter presenter) {
        this.mPresenter = presenter;
    }

    @Override
    public Context getContext() {
        return this;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.onDestroyPresenter();
            mPresenter = null;
        }
    }
}
